<!-- 备品弹窗 -->

<template>
  <WebModal path="backup" title="备品选择" :onSubmit="toChoose">
    <BackupSearch />
    <BackupTable />
  </WebModal>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'BackupModal',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixWeb(), CORE.mixWeb('backup', 'backup_')],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听备品弹窗
     */
    backup_visible(visible) {
      visible ? this.toReset() : this.toClear()
    },
  },

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 点击选择
     */
    toChoose() {
      this.one.children = this.backup_param.rowList.map((item) => ({ ...item, operateNum: 1 }))
      this.backup_closeModal()
    },

    /**
     * 重置选择
     */
    toReset() {
      this.backup_param.rowList = this.one.children || []
      this.backup_param.idList = this.backup_param.rowList.map(({ id }) => id)
    },

    /**
     * 清空选择
     */
    toClear() {
      this.backup_param.rowList = []
      this.backup_param.idList = []
    },
  },
}
</script>
